<?php

function process_ca_questionbank() {

global $smarty, $function;
	$a = isset($_GET['a']) ? $_GET['a'] : "";
	$oQbank = new Questionbank(); // class database of Question bank
	
	switch(strtolower($a)) {
	
		// action manage question bank, show list of questions
		default:
		case "manage":
			
			$list_question_banks = $oQbank->getAllQuestionsBank();
			$smarty->assign("list_questions_bank", $list_question_banks);			
			return $smarty->fetch("questionbank/manage.html");  // all html pages relates question bank should be in folder questionbank for easier in management
		break;
		
		// action insert question bank
		case "insert":
			if(isset($_POST['btn_submit'])) {
				$data['Question'] = stripslashes($function->FixQuotes($_POST['Question']));
				$data['ModeAnswer'] = stripslashes($function->FixQuotes($_POST['ModeAnswer']));
				$data['Answer'] = stripslashes($function->FixQuotes($_POST['Answer']));
				$data['Mark'] = intval($_POST['Mark']); 
				
				$data['Option1'] = stripslashes($function->FixQuotes($_POST['Option1']));
				$data['Option2'] = stripslashes($function->FixQuotes($_POST['Option2']));
				$data['Option3'] = stripslashes($function->FixQuotes($_POST['Option3']));
				$data['Option4'] = stripslashes($function->FixQuotes($_POST['Option4']));
				$data['Option5'] = stripslashes($function->FixQuotes($_POST['Option5']));
				$data['SystemAnswerOption1'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption1']));
				$data['SystemAnswerOption2'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption2']));
				$data['SystemAnswerOption3'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption3']));
				$data['SystemAnswerOption4'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption4']));
				$data['SystemAnswerOption5'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption5']));
				
				$good = $oQbank->insert_Question_Bank($data);
				if($good) {
					return $function->goto_url("?mod=questionbank&a=manage");
				} else {
					return $function->msg_box("Error in processing. Please try again.",2,"?mod=questionbank&a=insert");
				}
			} else {
				$smarty->assign('myOptions', array(
                                0 => '2 options',
                                1 => 'Multi choices',
                                2 => 'Short Answer',
                                3 => 'Text Answer')
                                );				

				$smarty->assign('myStatusOptions', array(
                                1 => 'Enable',
                                0 => 'Disable')
                                );
								
				return $smarty->fetch("questionbank/addquestionbank.html");
			}
		break;
		case "editquestion":
			if(isset($_POST['btn_submit'])) {
				$data['QuestionBankID'] = intval($_POST['QuestionBankID']); 
				$data['Question'] = stripslashes($function->FixQuotes($_POST['Question']));
				$data['ModeAnswer'] = stripslashes($function->FixQuotes($_POST['ModeAnswer']));
				$data['Answer'] = stripslashes($function->FixQuotes($_POST['Answer']));
				$data['Mark'] = intval($_POST['Mark']); 
				$data['Status'] = intval($_POST['Status']); 

				$data['Option1'] = stripslashes($function->FixQuotes($_POST['Option1']));
				$data['Option2'] = stripslashes($function->FixQuotes($_POST['Option2']));
				$data['Option3'] = stripslashes($function->FixQuotes($_POST['Option3']));
				$data['Option4'] = stripslashes($function->FixQuotes($_POST['Option4']));
				$data['Option5'] = stripslashes($function->FixQuotes($_POST['Option5']));
				$data['SystemAnswerOption1'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption1']));
				$data['SystemAnswerOption2'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption2']));
				$data['SystemAnswerOption3'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption3']));
				$data['SystemAnswerOption4'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption4']));
				$data['SystemAnswerOption5'] = stripslashes($function->FixQuotes($_POST['SystemAnswerOption5']));
				
				$good = $oQbank->update_Question_Bank($data);
				if($good) {
					//echo "good";
					return $function->goto_url("?mod=questionbank&a=manage");
				} else {
					//echo "not good";
					return $function->msg_box("Error in processing. Please try again.",2,"?mod=questionbank&a=edit");
				}
			} else {
				$qbid = isset($_GET['qbid']) ? intval($_GET['qbid']) : 0;
				$detail = $oQbank->getQuestionBankDetail($qbid);
				$smarty->assign("detail", $detail);
				$smarty->assign('myOptions', array(
                                0 => '2 options',
                                1 => 'Multi choices',
                                2 => 'Short Answer',
                                3 => 'Text Answer')
                                );
				$smarty->assign('mySelect', $detail['ModeAnswer']);		

				$smarty->assign('myStatusOptions', array(
                                1 => 'Enable',
                                0 => 'Disable')
                                );
				$smarty->assign('myStatusSelect', $detail['Status']);		
				
			  
				return $smarty->fetch("questionbank/editquestionbank.html");
			}
		break;
		
		case "deletequestion":
			if(isset($_POST['btn_submit'])) {
				$QuestionBankID = intval($_POST['QuestionBankID']);				
				$ok = intval($_POST['ok']);
				if($ok == 1) {
					$oQbank->delete_question_bank($QuestionBankID);
					return $function->msg_box("Delete OK.",2,"?mod=questionbank&a=manage");
				} else {
					return $function->msg_box("Error in processing. Please try again.",2,"?mod=questionbank");
				}
			} else {
				$qbid = isset($_GET['qbid']) ? intval($_GET['qbid']) : 0;
				$detail = $oQbank->getQuestionBankDetail($qbid);
				$smarty->assign("detail", $detail);
				return $smarty->fetch("questionbank/deletequestionbank.html");
			}
		break;
		
	}

}

?>